﻿/*********************弘石项目三组************************
*  功能描述：绩效管理：奖金
*  作者：刘伟康
*  时间：2021-12-23
*  修改人：刘伟康
*  修改时间：2021-12-23
*********************弘石项目三组************************/
using Hong.Business.Business_AssessmentManagement;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MiniExcelLibs;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace WeHongshibApI.Controllers.Controllers_AssessmentManagement
{
    [ApiExplorerSettings(GroupName = "Assessment")]
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class AssBonuController : ControllerBase
    {
        #region 构造器注入
        private readonly AssBonusBusiness _dal;
        public AssBonuController(AssBonusBusiness dal)
        {
            _dal = dal;
        }
        #endregion

        #region 项目奖金调整
        /// <summary>
        /// 项目奖金调整
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetAssessmentList()
        {
            var list = _dal.GetAssessmentList();
            return Ok(list);
        }

        #region 查看
        /// <summary>
        /// 查看
        /// </summary>
        /// <param name="DepId"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetViewBusnPerDep(int? DepId, string AssId)
        {
            var list = _dal.GetViewBusnPerDep(DepId, AssId);
            return Ok(list);
        }
        #endregion
        #endregion

        #region 部门奖金分配
        /// <summary>
        /// 部门奖金分配
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetBounDepListView(string AssId)
        {
            var list = _dal.GetBounDepListView(AssId);
            return Ok(list);
        }
        #region 导出excel
        /// <summary>
        /// 导出
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult Downloadexcel()
        {
            var list = _dal.GetBounDepListView(null);
            var values = new List<Dictionary<string, string>>();
            foreach (var item in list)
            {
                values.Add(new Dictionary<string, string> {
                    {"部门奖金计算主键",$"{item.CulaId}" },{"平均月工资",$"{item.CulaAge}" },{"部门绩效",$"{item.CulaAchie}" },
                    {"项目奖金占比",$"{item.CulaProportion}" },{"部门总奖金",$"{item.CulaSum}" },{"月工资倍数",$"{item.Culamultiple}" },
                    {"项目奖金",$"{item.CulaProjectbonus}" },{"部门奖金占比",$"{item.CulaProporbonus}" },{"部门内奖金",$"{item.CulaDepBouns}" },
                    {"2021上半年",$"{item.CulaYearTop}" },{"2021下半年",$"{item.CulaYearlower}" },{"部门主键",$"{item.DepId}" },     
                    {"部门名称",$"{item.DepName}" } ,{"任务主键",$"{item.AssId}" }

                });
            }
            var memoryStream = new MemoryStream();
            memoryStream.SaveAs(values);
            memoryStream.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(memoryStream, "applicatio/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = "部门奖金分配.xlsx"
            };
        }
        #endregion
        #endregion

        #region 部门内奖金计算
        /// <summary>
        /// 部门内奖金计算显示
        /// </summary>
        /// <param name="AssId"></param>
        /// <returns></returns>
        public IActionResult GetDepList(string AssId)
        {
            var list = _dal.GetDepList(AssId);
            return Ok(list);
        }
        #region 导出excel
        /// <summary>
        /// 导出
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult Downloadexcel1()
        {
            var list = _dal.GetDepList(null);
            var values = new List<Dictionary<string, string>>();
            foreach (var item in list)
            {
                values.Add(new Dictionary<string, string> {
                    {"姓名",$"{item.Bname}" },{"基本工资",$"{item.Basepay}" },{"工作时间/月",$"{item.Bworkinghours}" },
                    {"平均月工资",$"{item.BavgMounth}" },{"自评互评",$"{item.Bmutual}" },{"排名1",$"{item.Border1}" },
                    {"部门经理评价",$"{item.Bevaluation}" },{"排名2",$"{item.Border2}" },{"加权系数",$"{item.Bweighting}" },
                    {"部门内奖金计算值",$"{item.BonusValue}" },{"部门内奖金经理调整",$"{item.Badjustment}" },{"部门内奖金调整值",$"{item.BadjustmentValue}" },
                    {"优秀员工奖",$"{item.Baward}" } ,{"合计（含预发）",$"{item.Btotal1}" },{"预发奖金",$"{item.Badvancebonus}" },{"合计",$"{item.Btotal2}" },
                    {"工资倍数",$"{item.Bwagemultiple}" } ,{"2017上半年（含预发）",$"{item.Bfirsthalf}" },{"差值1",$"{item.Bdifference1}" },{"2016下半年（含预发）",$"{item.Bsecondhalf}" },
                    {"差值2",$"{item.Bdifference2}" }
                });
            }
            var memoryStream = new MemoryStream();
            memoryStream.SaveAs(values);
            memoryStream.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(memoryStream, "applicatio/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = "部门内奖金计算.xlsx"
            };
        }
        #endregion
        #endregion

        #region 部门奖金分配详情
        /// <summary>
        /// 部门奖金分配详情显示查询
        /// </summary>
        /// <param name="DepName"></param>
        /// <param name="AssId"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetmentDep(int? DepId, string AssId)
        {
            var list = _dal.GetmentDep(DepId, AssId);
            return Ok(list);
        }
        #region 部门
        /// <summary>
        /// 部门
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetDepartments()
        {
            var list = _dal.GetDepartments();
            return Ok(list);
        }
        #endregion
        #endregion

        #region 年度总奖金
        /// <summary>
        /// 年度总奖金显示查询
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetViewAnnDepList(int? DepId, string AssId)
        {
            var list = _dal.GetViewAnnDepList(DepId, AssId);
            return Ok(list);
        }
        #endregion
    }
}
